package com.efounder.holder;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.efounder.bean.GoodSkusBean;
import com.efounder.bean.GoodsBean;
import com.efounder.mobilemall.R;
import com.pansoft.openplanet.util.TCMathUtil;

import java.util.List;

/**
 * Created by Marcello on 2018/9/17.
 */
public class CreateOrderHolder extends BaseHolder<GoodsBean> {


    private ImageView imageView;
    private TextView tvItemPrice, tvItemCount, tvItemDesc, tvItemTitle;

    public CreateOrderHolder(ViewGroup parent, int resId) {
        super(parent, resId);
        imageView = getView(R.id.id_iv_logo);
        tvItemPrice = getView(R.id.tv_item_price);
        tvItemCount = getView(R.id.item_count);
        tvItemDesc = getView(R.id.tv_item_desc);
        tvItemTitle = getView(R.id.tv_item_title);

    }

    @Override
    public void setData(GoodsBean goodBean) {
        if (goodBean.getGoodSkus() != null && goodBean.getGoodSkus().size() > 0) {
            tvItemPrice.setText(goodBean.getMallGoodPrice().getPriceUnit() + " " + TCMathUtil
                    .retainAsignDecimalsWithZero(goodBean.getGoodSkus().get(0).getSkuPrice(), 2));
            List<GoodSkusBean.AttributeContentListBean> attrList = goodBean.getGoodSkus().get(0).getAttributeContentList();
            StringBuilder stringBuilder = new StringBuilder();
            for (int j = 0; j < attrList.size(); j++) {
                stringBuilder.append(attrList.get(j).getVIdName())
                        .append("；");
            }
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            tvItemDesc.setText(stringBuilder);
            tvItemTitle.setText(goodBean.getGoodSkus().get(0).getPropertiesName());
        } else {
            double price = goodBean.getMallGoodPrice().getPrice();
            String s = TCMathUtil.retainAsignDecimalsWithZero(price, 2);
            tvItemPrice.setText("￥" + s);
            tvItemDesc.setText(goodBean.getDescription());
            tvItemTitle.setText(goodBean.getGoodName());
        }
        tvItemCount.setText("x" + goodBean.getOrderGoodNum());
        Glide.with(getContext())
                .load(goodBean.getGoodCover())
                .apply(new RequestOptions().fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .skipMemoryCache(false))
                .into(imageView);

    }


}
